/*******************************************************
*文件名：windowmammager.cpp
*创建人：buptsoft团队
*创建日期：2014/3/19
*修改人：
*日期:
*描述：包含了Windowmanager类以及其相应需要的组件，Windowmanager
*     类用于管理Screenmanager类，并且完成绝大部分的绘制工作，软件
*     的帧率也由该类决定.
*版本：v0.0.5 buptsoftCopyright(c).
********************************************************/
#include"screenmanager.cpp"
#include"mainwindow.h"
#include<QTextStream>
#include<QFile>
#include<QClipboard>
#include<windows.h>
#include<qfiledialog.h>
using namespace std;
class Windowmanager{
public:
private:
    MainWindow * POINTER_M;
    Screenmanager * POINTER_S;
    Screenmanager * screen[16];
    Screenmanager * buffer,*buffer2,*buffer3,*buffer4,*searchbuffer;
    QPixmap *picy;
    QPixmap back1,plane1,menu1,menu2,menu3,menu4,dialog1,TXTlogo,p0,p1,wheel,r_menu,botton1,botton2,botton3,botton4,shadow1,needle,line,posbotton;
    QPixmap line_big,headline,back1_1,back2_1,back2_2,back2_3,back3_1,back3_2,cover,block1,shadow2,preback;
    int TICKS_PER_SECOND = 20;
    int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
    int MAX_FRAMESKIP = 10;
    long next_game_tick=clock();
    int loops;
    int MOUSE_PRESS_X=0,MOUSE_PRESS_Y=0,needle_x,needle_y,X_LEFT,X_RIGHT,Y_UP,Y_DOWN,rool_x=0,rool_y=0;
    int r_menu_x=0,r_menu_y=0;
    bool res_left_catch=FALSE;
    int page=10,dragstate=0;
    int currentfile=0;
    int lastpage=10;
    int piccount=10,line_x=0,sline_x=0,window_mx=0,window_my=0;
    int windoww=0,windowh=0,dialogx=195,dialogy=181,dialog_lp_x=0,dialog_lp_y=0;
public:
    /*******************************************************
    *函数名：Windowmanager()
    *功能:对Windowmanager类中的所有变量初始化
    *返回值：无返回值
    *参数：无参数
    *备注：该函数在初始化时必须调用
    ********************************************************/
    Windowmanager(MainWindow* m){
        for(int i=0;i<16;i++){
            screen[i]=NULL;
        }
        POINTER_M=m;
        POINTER_M->centralWidget()->setMouseTracking(TRUE);
        POINTER_M->setMouseTracking(TRUE);
        POINTER_M->setAcceptDrops(true);
        windoww=POINTER_M->width();
        windowh=POINTER_M->height();
        picy=&(m->pic);
        screen[0]=new Screenmanager("test.txt",25);
        needle_x=220;
        needle_y=65;
        buffer=new Screenmanager("TEMP.txt");
        buffer->note_to_head();
        buffer->set_size(320,250,480,290);
        buffer2=new Screenmanager("TEMP.txt");
        buffer2->note_to_head();
        buffer2->set_size(320,305,480,350);
        buffer3=new Screenmanager("TEMP.txt");
        buffer3->note_to_head();
        buffer3->set_size(320,250,480,320);
        buffer4=new Screenmanager("TEMP.txt");
        buffer4->note_to_head();
        buffer4->set_size(320,250,480,290);
        searchbuffer=new Screenmanager("TEMP.txt");
        searchbuffer->note_to_head();
        searchbuffer->set_size(664,7,767,30);
        POINTER_S=screen[0];
        back1.load("image/back1.png");
        back1_1.load("image/back1-1.png");
        back2_1.load("image/back2-1.png");
        back2_2.load("image/back2-2.png");
        back2_3.load("image/back2-3.png");
        back3_1.load("image/back3-1.png");
        back3_2.load("image/back3-2.png");
        plane1.load("image/plane1.png");
        menu1.load("image/menu1.png");
        menu2.load("image/menu2.png");
        menu3.load("image/menu3.png");
        menu4.load("image/menu4.png");
        dialog1.load("image/dialog1.png");
        TXTlogo.load("image/TXTlogo.png");
        p0.load("image/p0.png");
        p1.load("image/p1.png");
        wheel.load("image/wheel.png");
        r_menu.load("image/r_menu.png");
        botton1.load("image/botton1.png");
        botton2.load("image/botton2.png");
        botton3.load("image/botton3.png");
        botton4.load("image/botton4.png");
        shadow1.load("image/shadow1.png");
        needle.load("image/needle.png");
        line.load("image/line.png");
        line_big.load("image/line_big.png");
        posbotton.load("image/posbotton.png");
        headline.load("image/headline.png");
        cover.load("image/cover.png");
        block1.load("image/block1.png");
        shadow2.load("image/shadow2.png");
        preback.load("image/preback.png");
        X_LEFT=220;
        X_RIGHT=730;
        Y_UP=100;
        Y_DOWN=550;
    }
    /*******************************************************
    *函数名：run()
    *功能:开启软件主循环，主循环由TICKS_PER_SECOND决定软件帧率，主循
    *    环思路为：在保证逻辑帧按既定帧率运行的情况下，尽可能快地进行渲
    *    染，最大跳帧数由MAX_FRAMESKIP决定.
    *返回值：无返回值
    *参数：无参数
    *备注：该函数是一个死循环，建议在线程中加载，该函数如果退出，整个软件
    *     将会瘫痪.
    ********************************************************/
    void run(){
        // TODO Auto-generated method stub
                while(1){
                    loops=0;
                    while(clock()>next_game_tick  && loops < MAX_FRAMESKIP) {
                            if(1)update();
                        next_game_tick += SKIP_TICKS;
                        loops++;
                    }
                    if(loops==1)print();
                    else Sleep(2);
                }
    }
private:
    void clear_states(){
        POINTER_M->KEY_PRESSED=FALSE;
        POINTER_M->MOUSE_PRESSED=FALSE;
        POINTER_M->MOUSE_MOVE=FALSE;
        POINTER_M->MOUSE_RELEASED=FALSE;
        POINTER_M->MOUSE_SHIFT=FALSE;
        POINTER_M->RIGHT_PRESSED=FALSE;
    }
    void key_respond(){
       if(page/10==3){
           if(POINTER_M->MOUSE_PRESSED){
               if(dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<dialog1.width()+dialogx&&dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<20+dialogy){
                    dragstate=6;
                    dialog_lp_x=POINTER_M->MOUSE_X;
                    dialog_lp_y=POINTER_M->MOUSE_Y;
               }
           }else if(POINTER_M->MOUSE_RELEASED){
               dragstate=0;
           }else if(dragstate==6){
               dialogx+=POINTER_M->MOUSE_X-dialog_lp_x;
               dialogy+=POINTER_M->MOUSE_Y-dialog_lp_y;
               dialog_lp_x=POINTER_M->MOUSE_X;
               dialog_lp_y=POINTER_M->MOUSE_Y;
               buffer->set_size(dialogx-195+320,dialogy-181+250,dialogx-195+480,dialogy-181+290);
               buffer2->set_size(dialogx-195+320,dialogy-181+305,dialogx-195+480,dialogy-181+350);
               buffer3->set_size(dialogx-195+320,dialogy-181+250,dialogx-195+480,dialogy-181+320);
               buffer4->set_size(dialogx-195+320,dialogy-181+250,dialogx-195+480,dialogy-181+290);
           }
       }
       if(page==12){
             if(POINTER_M->KEY_PRESSED){
                POINTER_M->KEY_PRESSED=FALSE;
                switch(POINTER_M->KEY_NUM){
                     case -1:searchbuffer->to_last_line();break;
                     case -2:searchbuffer->to_next_line();break;
                     case -3:searchbuffer->note_left();break;
                     case -4:searchbuffer->note_right();break;
                     case -5:searchbuffer->Backspace();break;
                     case -6:searchbuffer->Delete();break;
                     case -7:page=10;break;
                     case -8:page=10;break;
                     case  1:searchbuffer->insert(POINTER_M->string);break;
                     case  2:POINTER_S->search(searchbuffer->return_headF());break;
                }
             }
             else if(POINTER_M->MOUSE_PRESSED){
                     MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                     MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                     if(!searchbuffer->inside_region(MOUSE_PRESS_X,MOUSE_PRESS_Y)){
                          page=10;
                     }else {
                         POINTER_M->MOUSE_PRESSED=FALSE;
                         searchbuffer->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,1);
                     }
             }
             if(POINTER_M->MOUSE_X<=327&&POINTER_M->MOUSE_Y<=37)
                 page=10;
             if(POINTER_M->MOUSE_SHIFT||POINTER_M->RIGHT_PRESSED||POINTER_M->WHEEL_PRESSED)
                 page=10;
        }if(page==10){
            boolean draged_down=FALSE;
            if(dragstate==3){
                if(POINTER_M->MOUSE_Y>rool_y){
                    for(int i=0;i<(POINTER_M->MOUSE_Y-rool_y)/20;i++)
                        POINTER_S->rool_down();
                }else
                    for(int i=0;i<-(POINTER_M->MOUSE_Y-rool_y)/20;i++)
                        POINTER_S->rool_up();
            }else if(dragstate==1){
                if(POINTER_M->MOUSE_Y>Y_DOWN){
                        POINTER_S->rool_down(),draged_down=TRUE;
                }else if(POINTER_M->MOUSE_Y<Y_UP){
                        POINTER_S->rool_up(),draged_down=TRUE;
                }
            }else if(dragstate==4){
                if(X_LEFT<POINTER_M->MOUSE_X&&X_RIGHT>POINTER_M->MOUSE_X){
                    needle_x=(POINTER_M->MOUSE_X);
                }else if(X_LEFT>POINTER_M->MOUSE_X)
                    needle_x=X_LEFT;
                else
                    needle_x=X_RIGHT;
            }
            if(POINTER_M->KEY_PRESSED){
                POINTER_M->KEY_PRESSED=FALSE;
                switch(POINTER_M->KEY_NUM){
                     case -1:POINTER_S->to_last_line();break;
                     case -2:POINTER_S->to_next_line();break;
                     case -3:POINTER_S->note_left();break;
                     case -4:POINTER_S->note_right();break;
                     case -5:POINTER_S->Backspace();break;
                     case -6:POINTER_S->Delete();break;
                     case -7:for(int i=0;i<POINTER_M->ROOL_NUM;i++)POINTER_S->rool_up();res_left_catch=TRUE;break;
                     case -8:for(int i=0;i<POINTER_M->ROOL_NUM;i++)POINTER_S->rool_down();res_left_catch=TRUE;break;
                     case -9:POINTER_S->copy();POINTER_M->write_to_clickboard(POINTER_S->return_block());break;
                     case -10:POINTER_S->paste();break;
                     case -11:POINTER_S->save();break;
                     case -12:POINTER_S->cut();POINTER_M->write_to_clickboard(POINTER_S->return_block());break;
                     case -13:POINTER_S->page_up();break;
                     case -14:POINTER_S->page_down();break;
                     case -15:POINTER_S->home_pressed();break;
                     case -16:{char str[128]="\t";POINTER_S->insert(str);}break;
                     case  1:POINTER_S->insert(POINTER_M->string);break;
                     case  2:{
                                char str[128]="\n";
                                char str1[128]=" ";
                                POINTER_S->insert(str);
                                for(int i=X_LEFT;i<needle_x;i+=POINTER_S->get_lettersize()/2)
                                    POINTER_S->insert(str1);
                             }
                            break;
                }
                POINTER_M->KEY_NUM=0;
            }
            else if(POINTER_M->MOUSE_RELEASED){
                POINTER_M->MOUSE_RELEASED=FALSE;
                res_left_catch=FALSE;
                dragstate=0;
            }if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                if(4<MOUSE_PRESS_X&&MOUSE_PRESS_X<86&&1<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<35){
                    page=20;
                }else if(30<MOUSE_PRESS_X&&MOUSE_PRESS_X<120&&85<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<85+25*16){
                    if(screen[(MOUSE_PRESS_Y-85)/25])
                        POINTER_S=screen[(MOUSE_PRESS_Y-85)/25];
                }else if(needle_x-needle.width()/2<MOUSE_PRESS_X&&MOUSE_PRESS_X<needle_x+needle.width()/2&&needle_y<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<needle_y+needle.height()){
                    dragstate=4;
                }else if(88<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<162&&1<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<35)
                    page=36;
                else if(166<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<235&&1<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<35)
                    POINTER_S->save();
                else if(239<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<316&&1<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<35)
                    new_file("help.txt");
                else if(POINTER_S->inside_region(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y)){
                    POINTER_S->clear_res();
                    POINTER_S->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,1);
                    res_left_catch=FALSE;
                    dragstate=1;
                }else if(searchbuffer->inside_region(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y))
                    page=12;
                else if(windoww-800+750<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<windoww-800+790&&73+POINTER_S->return_curlines()*(p0.height()*windowh/600-47)/(POINTER_S->total_lines()+1)<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<111+POINTER_S->return_curlines()*(p0.height()*windowh/600-47)/(POINTER_S->total_lines()+1)){
                    dragstate=2;
                }
            }else if(POINTER_M->WHEEL_PRESSED){
                POINTER_M->WHEEL_PRESSED=FALSE;
                if(POINTER_S->inside_region(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y)){
                    rool_x=POINTER_M->MOUSE_X;
                    rool_y=POINTER_M->MOUSE_Y;
                    dragstate=3;
                }
            }else if(draged_down||POINTER_M->MOUSE_MOVE){
                POINTER_M->MOUSE_MOVE=FALSE;
                if(dragstate==2){
                    POINTER_S->set_line((POINTER_M->MOUSE_Y-93)*(POINTER_S->total_lines()+1)/(p0.height()*windowh/600-47));
                }else if(dragstate==1){
                    POINTER_S->clear_note();
                    if(POINTER_S->inside_region(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y))
                            POINTER_S->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,3);
                    else if(X_LEFT<POINTER_M->MOUSE_X&&X_RIGHT>POINTER_M->MOUSE_X&&POINTER_M->MOUSE_Y>Y_DOWN){
                            POINTER_S->rool_down();
                            POINTER_S->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,4);
                    }else if(X_LEFT<POINTER_M->MOUSE_X&&X_RIGHT>POINTER_M->MOUSE_X&&POINTER_M->MOUSE_Y<Y_UP-POINTER_S->get_lettersize()){
                            POINTER_S->rool_up();
                            POINTER_S->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,5);
                    }
                    POINTER_S->res_check();

                }
            }else if(POINTER_M->MOUSE_SHIFT){
                POINTER_M->MOUSE_SHIFT=FALSE;
                POINTER_S->mouse_shift_click(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y);
            }else if(POINTER_M->RIGHT_PRESSED){
                POINTER_M->RIGHT_PRESSED=FALSE;
                int x=POINTER_M->MOUSE_X;
                int y=POINTER_M->MOUSE_Y;
                if(POINTER_S->inside_region(x,y)){
                    r_menu_x=POINTER_S->inside_region(x+r_menu.width(),y)?x:x-r_menu.width();
                    r_menu_y=POINTER_S->inside_region(x,y+r_menu.height())?y:y-r_menu.height();
                    page=11;
                }
            }else if(POINTER_M->FILE_DRAGGED){
                POINTER_M->FILE_DRAGGED=FALSE;
                this->new_file(POINTER_M->file);
            }else if(POINTER_M->CTRL_ROOLUP){
                POINTER_M->CTRL_ROOLUP=FALSE;
                POINTER_S->lettersize_up(POINTER_M->ROOL_NUM);
            }else if(POINTER_M->CTRL_ROOLDOWN){
                POINTER_M->CTRL_ROOLDOWN=FALSE;
                POINTER_S->lettersize_down(POINTER_M->ROOL_NUM);
            }
        }else if(page==11){
            if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X-r_menu_x;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y-r_menu_y;
                if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&15<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<35){
                    POINTER_S->copy();POINTER_M->write_to_clickboard(POINTER_S->return_block());page=10;
                }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&35<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<60){
                    POINTER_S->cut();POINTER_M->write_to_clickboard(POINTER_S->return_block());page=10;
                }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&60<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<85){
                    POINTER_S->paste();page=10;
                }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&110<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<140){
                    page=30;
                }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&140<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<165){
                    POINTER_S->save();page=10;
                }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&165<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<190){
                    close_file();page=10;
                }else
                    page=10;
            }
        }else if(page==20){
            if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                if(4<MOUSE_PRESS_X&&MOUSE_PRESS_X<86&&1<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<35){
                    page=10;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
                    page=21;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                    page=22;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                    POINTER_S->save();
                    POINTER_S->store();
                    page=10;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<207){
                    exit(0);
                }

            }
        }else if(page==21){
            if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                if(4<MOUSE_PRESS_X&&MOUSE_PRESS_X<86&&1<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<35){
                    page=10;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
                    page=20;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                    page=22;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                    page=30;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
                    page=31;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                    page=38;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<208){
                    page=23;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                    POINTER_S->save();
                    page=10;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<207){
                    exit(0);
                }
            }
        }else if(page==22){
            if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                if(4<MOUSE_PRESS_X&&MOUSE_PRESS_X<86&&1<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<35){
                    page=10;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                    page=20;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
                    page=21;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                    page=35;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
                    page=36;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                    page=37;
                }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<207){
                    close_file();
                    page=10;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                    POINTER_S->save();
                    page=10;
                }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<207){
                    exit(0);
                }

            }
        }else if(page==23){
           if(POINTER_M->MOUSE_PRESSED){
               POINTER_M->MOUSE_PRESSED=FALSE;
               MOUSE_PRESS_X=POINTER_M->MOUSE_X;
               MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
               if(322<MOUSE_PRESS_X&&MOUSE_PRESS_X<470&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                   POINTER_S->read();page=10;
               }else if(322<MOUSE_PRESS_X&&MOUSE_PRESS_X<470&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<208){
                   POINTER_S->store();page=10;
               }
           }
        }else if(page==30||page==31){
            if(POINTER_M->KEY_PRESSED){
                POINTER_M->KEY_PRESSED=FALSE;
                switch(POINTER_M->KEY_NUM){
                     case -1:buffer->to_last_line();break;
                     case -2:buffer->to_next_line();break;
                     case -3:buffer->note_left();break;
                     case -4:buffer->note_right();break;
                     case -5:buffer->Backspace();break;
                     case -6:buffer->Delete();break;
                     case -16:{char str[5]="    ";buffer->insert(str);}break;
                     case  1:buffer->insert(POINTER_M->string);break;
                     case  2:if(page==30){POINTER_S->search(buffer->return_headF());}else if(POINTER_S->search(buffer->return_headF())){
                        POINTER_S->Delete();
                        POINTER_S->insert_filelink(buffer2->return_headF());
                        POINTER_S->rool_up();
                    }page=10;break;
                }
                POINTER_M->KEY_NUM=0;
            }
            if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                buffer->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,1);
                if(32<MOUSE_PRESS_X&&MOUSE_PRESS_X<87&&20<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<75){
                    page=10;
                }else if(52+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<178+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                    if(page==30)
                        POINTER_S->search(buffer->return_headF());
                    else if(POINTER_S->search(buffer->return_headF())){
                        POINTER_S->Delete();
                        POINTER_S->insert_filelink(buffer2->return_headF());
                        POINTER_S->rool_up();
                    }
                    page=10;
                }else if(230+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<363+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                    page=10;
                }else if(page==31&&buffer2->inside_region(MOUSE_PRESS_X,MOUSE_PRESS_Y)){
                    page=32;
                }
            }
        }else if(page==32){
            if(POINTER_M->KEY_PRESSED){
                POINTER_M->KEY_PRESSED=FALSE;
                switch(POINTER_M->KEY_NUM){
                     case -1:buffer2->to_last_line();break;
                     case -2:buffer2->to_next_line();break;
                     case -3:buffer2->note_left();break;
                     case -4:buffer2->note_right();break;
                     case -5:buffer2->Backspace();break;
                     case -6:buffer2->Delete();break;
                     case -16:{char str[5]="    ";buffer2->insert(str);}break;
                     case  1:buffer2->insert(POINTER_M->string);break;
                     case  2:if(POINTER_S->search(buffer->return_headF())){
                         POINTER_S->Delete();
                         POINTER_S->insert_filelink(buffer2->return_headF());
                         POINTER_S->rool_up();
                     }page=10;break;
                }
                POINTER_M->KEY_NUM=0;
            }
            if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                buffer2->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,1);
                if(32<MOUSE_PRESS_X&&MOUSE_PRESS_X<87&&20<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<75){
                    page=10;
                }else if(52+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<178+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                    if(POINTER_S->search(buffer->return_headF())){
                        POINTER_S->Delete();
                        POINTER_S->insert_filelink(buffer2->return_headF());
                        POINTER_S->rool_up();
                    }
                    page=10;
                }else if(230+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<363+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                    page=10;
                }else if(buffer->inside_region(MOUSE_PRESS_X,MOUSE_PRESS_Y)){
                    page=31;
                }
            }
        }else if(page==35||page==36||page==37){
            if(POINTER_M->KEY_PRESSED){
                POINTER_M->KEY_PRESSED=FALSE;
                switch(POINTER_M->KEY_NUM){
                     case -1:buffer3->to_last_line();break;
                     case -2:buffer3->to_next_line();break;
                     case -3:buffer3->note_left();break;
                     case -4:buffer3->note_right();break;
                     case -5:buffer3->Backspace();break;
                     case -6:buffer3->Delete();break;
                     case -16:{char str[5]="    ";buffer3->insert(str);}break;
                     case  1:
                        if(POINTER_M->string[0]=='f'&&POINTER_M->string[1]=='i'&&POINTER_M->string[2]=='l'&&POINTER_M->string[3]=='e'&&POINTER_M->string[4]==':'&&POINTER_M->string[5]=='/'&&POINTER_M->string[6]=='/'&&POINTER_M->string[7]=='/')
                            buffer3->insert(POINTER_M->string+8);
                        else
                            buffer3->insert(POINTER_M->string);
                     break;
                     case  2:;break;
                }
            }
            POINTER_M->KEY_NUM=0;
            if(POINTER_M->MOUSE_PRESSED){
                POINTER_M->MOUSE_PRESSED=FALSE;
                MOUSE_PRESS_X=POINTER_M->MOUSE_X;
                MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
                buffer3->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,1);
                if(dialogx-195+518<MOUSE_PRESS_X&&MOUSE_PRESS_X<dialogx-195+551&&dialogy-181+266<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<dialogy-181+298){
                    char *str;
                    QByteArray ba;
                    if(page==37||page==35){
                        ba = POINTER_M->get_name(1).toLocal8Bit();
                        str=ba.data();
                        if(str[0])buffer3->clear(),buffer3->insert(str);
                    }else{
                        ba = POINTER_M->get_name(0).toLocal8Bit();
                        str=ba.data();
                        if(str[0])buffer3->clear(),buffer3->insert(str);
                    }
                }else if(32<MOUSE_PRESS_X&&MOUSE_PRESS_X<87&&20<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<75){
                    page=10;
                }else if(52+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<178+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                    if(page!=37)
                        new_file(buffer3->return_content());
                    else
                        POINTER_S->save(buffer3->return_content());
                    page=10;
                }else if(230+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<363+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                    page=10;
                }
            }

        }else if(page==38){
           if(POINTER_M->KEY_PRESSED){
               POINTER_M->KEY_PRESSED=FALSE;
               switch(POINTER_M->KEY_NUM){
                    case -1:buffer4->to_last_line();break;
                    case -2:buffer4->to_next_line();break;
                    case -3:buffer4->note_left();break;
                    case -4:buffer4->note_right();break;
                    case -5:buffer4->Backspace();break;
                    case -6:buffer4->Delete();break;
                    case -16:{char str[5]="    ";buffer->insert(str);}break;
                    case  1:buffer4->insert(POINTER_M->string);break;
                    case  2:break;
               }
               POINTER_M->KEY_NUM=0;
           }
           if(POINTER_M->MOUSE_PRESSED){
               POINTER_M->MOUSE_PRESSED=FALSE;
               MOUSE_PRESS_X=POINTER_M->MOUSE_X;
               MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;
               buffer3->seek_note(POINTER_M->MOUSE_X,POINTER_M->MOUSE_Y,1);
               if(32<MOUSE_PRESS_X&&MOUSE_PRESS_X<87&&20<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<75){
                   page=10;
               }else if(52+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<178+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                   POINTER_S->set_lettersize(buffer4->return_number());
                   page=10;
               }else if(230+dialogx<MOUSE_PRESS_X&&MOUSE_PRESS_X<363+dialogx&&163+dialogy<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<192+dialogy){
                   page=10;
               }
           }
       }

        clear_states();
    }
    /*******************************************************
    *函数名：update()
    *功能:进行逻辑帧的处理，逻辑帧执行的速度比渲染快很多
    *返回值：无返回值
    *参数：无参数
    *备注：按键操作的响应也在这个函数中处理
    ********************************************************/
    void update(){
        key_respond();
        MOUSE_PRESS_X=POINTER_M->MOUSE_X;
        MOUSE_PRESS_Y=POINTER_M->MOUSE_Y;

        if(next_game_tick%1000<500){
            POINTER_S->note_show=true;
            searchbuffer->note_show=(page==12);
            buffer->note_show=(page!=32)?true:false;
            buffer2->note_show=(page==32)?true:false;
            buffer3->note_show=true;
            buffer4->note_show=true;
        }
        else{
            POINTER_S->note_show=false;
            searchbuffer->note_show=false;
            buffer->note_show=false;
            buffer2->note_show=false;
            buffer3->note_show=false;
            buffer4->note_show=false;
        }
        if(page==10){
            POINTER_S->update();
            searchbuffer->update();
            if(4<MOUSE_PRESS_X&&MOUSE_PRESS_X<86&&1<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<35){
                page=20;
            }
            if(dragstate==2||windoww-800+750<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<windoww-800+800&&55<POINTER_M->MOUSE_Y){
                if(sline_x<30)
                    sline_x+=6;
                else if(line_x<30)
                    line_x+=6;
            }else{
                if(line_x==6)
                    sline_x=30;
                if(line_x>0)
                    line_x-=6;
                if(sline_x)
                    sline_x-=6;
            }
        }else if(page==12){
            if(dragstate==2||windoww-800+750<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<windoww-800+800&&55<POINTER_M->MOUSE_Y)
                page=10;
        }else if(page==20){
            if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
                 page=21;
            }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                 page=22;
            }
        }else if(page==21){
            if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){

            }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<208){
                page=23;
            }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99||10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171||10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<207){
                 if(piccount>1){
                     piccount-=2;
                 }else{
                     page=20;
                     piccount=5;
                 }
            }
        }else if(page==22){
            if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){

            }else if(10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135||10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171||10<MOUSE_PRESS_X&&MOUSE_PRESS_X<150&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<207){
                if(piccount>1){
                    piccount-=2;
                }else
                    if(page==20)
                        page=10;
                    else{
                        page=20;
                        piccount=5;
                    }
            }
        }else if(page==30||page==31){
            buffer->update();
        }else if(page==32){
            buffer2->update();
        }else if(page==35||page==36||page==37){
            buffer3->update();
        }else if(page==38){
            buffer4->update();
        }
        if(page/10==2&&page!=23){
            if(page==20&&(153<MOUSE_PRESS_X||MOUSE_PRESS_Y>344)||(314<MOUSE_PRESS_X||MOUSE_PRESS_Y>344)||(153<MOUSE_PRESS_X&&MOUSE_PRESS_Y>231)||(85<MOUSE_PRESS_X&&MOUSE_PRESS_Y<46)){
                    if(piccount>1){
                        piccount-=2;
                    }else
                        if(page==20)
                            page=10;
                        else{
                            page=20;
                            piccount=5;
                        }
            }
        }else if(page==23){
            if(!((320<MOUSE_PRESS_X&&470>MOUSE_PRESS_X&&MOUSE_PRESS_Y>130&&MOUSE_PRESS_Y<230)||(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<320&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<208))){
                if(piccount>1){
                    piccount-=2;
                }else
                    if(page==20)
                        page=10;
                    else{
                        page=21;
                        piccount=5;
                    }
            }
        }
        POINTER_M->BUFFER_FULL=POINTER_S->buffer_full();
        if(page!=lastpage){
            if(lastpage==10&&page==20||lastpage==20&&page==21||lastpage==20&&page==22||lastpage==21&&page==23)
                piccount=1;
            lastpage=page;
        }
        if(piccount<5){
           piccount++;
        }
        if(windoww!=POINTER_M->width()||windowh!=POINTER_M->height()){
            windoww=POINTER_M->width();
            windowh=POINTER_M->height();
            searchbuffer->set_size(windoww-136,8,windoww-33,30);
            for(int i=0;i<16&&screen[i];i++)
                screen[i]->set_size(220,90,windoww-50,windowh-50);
            X_RIGHT=windoww-50;
            Y_DOWN=windowh-50;
            dialogx=this->windoww/2-dialog1.width()/2;
            dialogy=this->windowh/2-dialog1.height()/2;
            buffer->set_size(dialogx-195+320,dialogy-181+250,dialogx-195+480,dialogy-181+290);
            buffer2->set_size(dialogx-195+320,dialogy-181+305,dialogx-195+480,dialogy-181+350);
            buffer3->set_size(dialogx-195+320,dialogy-181+250,dialogx-195+480,dialogy-181+320);
            buffer4->set_size(dialogx-195+320,dialogy-181+250,dialogx-195+480,dialogy-181+290);
            qDebug()<<windoww<<windowh;
        }
    }

    /*******************************************************
    *函数名：print()
    *功能:对界面进行渲染，执行速度比updata（）慢很多，甚至可能真用两帧之
    *    间的所有时间。
    *返回值：无返回值
    *参数：无参数
    *备注：若用时过长，建议采用跳帧处理.
    ********************************************************/
    void print(){
        QPainter pp(picy);
        pp.drawPixmap(0,0,windoww,windowh,back1_1);
        for(int i=5;i<=windoww-back2_3.width();i+=back2_2.width())
            pp.drawPixmap(i,0,back2_2);
        pp.drawPixmap(0,0,back2_1);
        pp.drawPixmap(windoww-back2_3.width(),0,back2_3);
        pp.drawPixmap(10,45,140,windowh-54,back3_1);
        pp.drawPixmap(163,45,windoww-177,windowh-54,back3_2);
        //pp.drawPixmap(0,0,back1);
        pp.drawPixmap(needle_x-needle.width()/2,needle_y,needle);
        if(line_x||sline_x==30&&(dragstate==2||730<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<800&&55<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<600)){
            pp.drawPixmap(753+windoww-800+30-line_x,71,line_big.width(),line_big.height()*windowh/600,line_big);
            pp.drawPixmap(753+windoww-800+30-line_x,71+POINTER_S->return_curlines()*(p0.height()*windowh/600-47)/(POINTER_S->total_lines()+1),p0);
        }else{
            pp.drawPixmap(763+windoww-800+sline_x,71,line.width(),line.height()*windowh/600,line);
            pp.drawPixmap(763+windoww-800+sline_x,71+POINTER_S->return_curlines()*(p0.height()*windowh/600-40)/(POINTER_S->total_lines()+1),posbotton);
        }
        POINTER_S->print(&pp);
        searchbuffer->print(&pp);
        for(int i=0;i<16&&screen[i];i++){
            pp.drawPixmap(0,25*i,TXTlogo);
            pp.drawText(QPoint(52,105+25*i-3),QString(QString::fromLocal8Bit(screen[i]->shortname)));
            if(screen[i]==POINTER_S)
                pp.drawPixmap(27,80+25*i+2,32+5.5*strlen(screen[i]->shortname),cover.height(),cover);
        }
        if(page==10){
            if(dragstate==4)
                 pp.drawPixmap(needle_x,needle_y+needle.height(),headline.width(),headline.height()*windowh/600,headline);
            if(dragstate==3)
                 pp.drawPixmap(rool_x-wheel.width()/2,rool_y-wheel.height()/2,wheel);
            if(88<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<162&&1<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<35)
                pp.drawPixmap(0,0,botton2);
            else if(166<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<235&&1<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<35)
                pp.drawPixmap(0,0,botton3);
            else if(239<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<316&&1<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<35)
                pp.drawPixmap(0,0,botton4);
        }else if((page==11)){
                 pp.drawPixmap(r_menu_x,r_menu_y,r_menu);
                 MOUSE_PRESS_X=POINTER_M->MOUSE_X-r_menu_x;
                 MOUSE_PRESS_Y=POINTER_M->MOUSE_Y-r_menu_y;
                 if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&15<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<35){
                     pp.drawPixmap(r_menu_x,r_menu_y+10,shadow2);
                 }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&35<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<60){
                     pp.drawPixmap(r_menu_x,r_menu_y+35,shadow2);
                 }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&60<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<85){
                     pp.drawPixmap(r_menu_x,r_menu_y+60,shadow2);
                 }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&110<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<140){
                     pp.drawPixmap(r_menu_x,r_menu_y+113,shadow2);
                 }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&140<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<165){
                     pp.drawPixmap(r_menu_x,r_menu_y+140,shadow2);
                 }else if(15<MOUSE_PRESS_X&&MOUSE_PRESS_X<70&&165<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<190){
                     pp.drawPixmap(r_menu_x,r_menu_y+165,shadow2);
                 }
        }else if(page==20){
            pp.drawPixmap(6+menu1.width()*(5-piccount)/19,35,menu1.width()*piccount/5,menu1.height()*piccount/5,menu1);
        }else if(page==21||page==23){
            pp.drawPixmap(6,35,menu1);
            pp.drawPixmap(0,36,shadow1);
            if(page!=23)
                pp.drawPixmap(152,47+menu2.height()*(5-piccount)/13,menu2.width()*piccount/5,menu2.height()*piccount/5,menu2);
            else
                pp.drawPixmap(152,47,menu2);
           if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                pp.drawPixmap(158,0,shadow1);
           }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
               pp.drawPixmap(158,36,shadow1);
           }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
               pp.drawPixmap(158,72,shadow1);
           }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<208){
               pp.drawPixmap(158,108,shadow1);
           }
           if(page==23){
               pp.drawPixmap(311,128+menu4.height()*(5-piccount)/8,menu4.width()*piccount/5,menu4.height()*piccount/5,menu4),pp.drawPixmap(158,108,shadow1);
               if(322<MOUSE_PRESS_X&&MOUSE_PRESS_X<470&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                   pp.drawPixmap(317,72,shadow1);
               }else if(322<MOUSE_PRESS_X&&MOUSE_PRESS_X<470&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<208){
                   pp.drawPixmap(317,108,shadow1);
               }
           }
        }else if(page==22){
            pp.drawPixmap(6,35,menu1);
            pp.drawPixmap(0,0,shadow1);
            if(page!=23)
                pp.drawPixmap(152,47+menu3.height()*(5-piccount)/30,menu3.width()*piccount/5,menu3.height()*piccount/5,menu3);
            else
                pp.drawPixmap(152,47,menu3);
            if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&65<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<99){
                pp.drawPixmap(158,0,shadow1);
            }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&101<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<135){
                pp.drawPixmap(158,36,shadow1);
            }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&137<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<171){
                pp.drawPixmap(158,72,shadow1);
            }else if(165<MOUSE_PRESS_X&&MOUSE_PRESS_X<307&&173<MOUSE_PRESS_Y&&MOUSE_PRESS_Y<201){
                pp.drawPixmap(158,108,shadow1);
            }
        }else if(page==30){
            pp.drawPixmap(dialogx,dialogy,dialog1);
            pp.drawPixmap(dialogx+319,dialogy+82,block1);
            pp.drawText(QPoint(dialogx-195+250,dialogy-181+230),QString("请输入搜索内容:"));
            buffer->print(&pp);
        }else if(page==31||page==32){
            pp.drawPixmap(dialogx,dialogy,dialog1);
            pp.drawPixmap(dialogx+319,dialogy+82,block1);
            pp.drawText(QPoint(dialogx-195+250,dialogy-181+230),QString("您要把:"));
            pp.drawText(QPoint(dialogx-195+250,dialogy-181+290),QString("替换成:"));
            buffer->print(&pp);
            buffer2->print(&pp);
        }else if(page==35||page==36||page==37){
            pp.drawPixmap(dialogx,dialogy,dialog1);
            if(page==35)
                pp.drawText(QPoint(dialogx-195+250,dialogy-181+230),QString("新建文件:"));
            else if(page==36)
                pp.drawText(QPoint(dialogx-195+250,dialogy-181+230),QString("打开文件:"));
            else if(page==37)
                pp.drawText(QPoint(dialogx-195+250,dialogy-181+230),QString("另存为:"));
            buffer3->print(&pp);
        }else if(page==38){
            pp.drawPixmap(dialogx,dialogy,dialog1);
            pp.drawPixmap(dialogx+319,dialogy+82,block1);
            pp.drawText(QPoint(dialogx-195+250,dialogy-181+230),QString("请输入新字号:"));
            buffer4->print(&pp);
        }
        if(page/10==1||page/10==3){

        }
        if(page/10==2){
            if(10<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<150&&101<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<135){
                pp.drawPixmap(0,36,shadow1);
            }else if(10<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<150&&65<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<99){
                pp.drawPixmap(0,0,shadow1);
            }else if(10<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<150&&137<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<171){
                pp.drawPixmap(0,72,shadow1);
            }else if(10<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<150&&173<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<207){
                pp.drawPixmap(0,108,shadow1);
            }
        }
        if(4<POINTER_M->MOUSE_X&&POINTER_M->MOUSE_X<86&&1<POINTER_M->MOUSE_Y&&POINTER_M->MOUSE_Y<35)
            pp.drawPixmap(0,0,botton1);
        POINTER_M->update();
    }
    void new_file(char * string){
        if(!screen[15]){
            int i=0;
            for(;i<16&&screen[i];i++);
            screen[i]=new Screenmanager(string,25);
            currentfile=i;
            POINTER_S=screen[i];
            screen[i]->set_size(220,90,windoww-50,windowh-50);
            POINTER_S->read();
        }
    }
    void close_file(){
        bool found=false;
        for(int i=0;i<15;i++){
            if(POINTER_S==screen[i])
                found=true;
            if(found)
                screen[i]=screen[i+1];
        }
        screen[15]=NULL;
        if(!screen[0])
            screen[0]=new Screenmanager("test.txt",25);
        screen[0]->set_size(220,90,windoww-50,windowh-50);
        POINTER_S=screen[0];
    }
};
